package com.ncloud.system.service.impl;

import com.ncloud.system.entity.Menu;
import com.ncloud.system.entity.Role;
import com.ncloud.system.entity.RoleMenu;
import com.ncloud.system.mapper.RoleMapper;
import com.ncloud.system.service.RoleService;
import com.ncloud.system.service.SequenceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by shiqiang on 2017/7/31.
 */
@Service
public class RoleServiceImpl implements RoleService{
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private RoleMapper roleMapper;
    @Autowired
    private SequenceService sequenceService;
    @Override
    public Long insertRole(Role role) {
        if(role.getCreateDate()==null){
            role.setCreateDate(new Date());
        }
        if(role.getRoleId()==null){
            Long id = sequenceService.getSequence("role_id_seq");
            role.setRoleId(id);
        }
        role.setUseTag("1");
        roleMapper.insertRole(role);
        return role.getRoleId();
    }

    @Override
    public int updateRole(Role role) {
        return roleMapper.updateRole(role);
    }

    @Override
    public Role getOneRole(Long roleId) {
        return roleMapper.getOneRole(roleId);
    }

    @Override
    public int insertRoleMenu(RoleMenu roleMenu) {
        return roleMapper.insertRoleMenu(roleMenu);
    }

    @Override
    public int deleteRoleMenu(Long roleId) {
        return roleMapper.deleteRoleMenu(roleId);
    }

    @Override
    public int deleteRole(Long roleId) {
        return roleMapper.deleteRole(roleId);
    }

    @Override
    public List<Role> getRolesByCompanyId(Long companyId) {
        return roleMapper.getRolesByCompanyId(companyId);
    }

    @Override
    public List<Menu> getMenusByRole(Long roleId) {
        return roleMapper.getMenusByRole(roleId);
    }

    @Override
    public List<Role> getRolesByAll() {
        return roleMapper.getRolesByAll();
    }

    @Override
    public List<Role> getRoleByDepart(Long departId, Long companyId) {
        return roleMapper.getRoleByDepart(departId,companyId);
    }

    @Override
    public int deleteRoleState(Long roleId) {
        return roleMapper.deleteRoleState(roleId);
    }

    @Override
    public int deleteRoleMenuState(Long roleId) {
        return roleMapper.deleteRoleMenuState(roleId);
    }
}
